﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Web.Mvc;
using Model.WaiGaoQiao;
using WaiGaoQiaoWeb.Models;
using WaiGaoQiaoWeb.JsonEntities;

namespace WaiGaoQiaoWeb.Controllers
{
    public class XiYiDayReportController : Controller
    {
        private XiYiDayReportInfo fundinfo = new XiYiDayReportInfo();
        public ActionResult XiYiDayReportIndex()
        {
            return View();
        }

        public ActionResult GetList(PageVM pvm)
        {
            string strDate = pvm.query;
            string[] sDate = new string[2];
            int icount = 0;
            sDate = strDate.Split('-');
            int yy = Convert.ToInt32(sDate[0]);
            int mm = Convert.ToInt32(sDate[1]);
            JsonFlexiGridData jsonFlexiGridData = new JsonFlexiGridData();
            jsonFlexiGridData.page = pvm.page;
            DataSet list = fundinfo.BindList(yy, mm, out icount);
            jsonFlexiGridData.total = icount;
            List<string> v;
            foreach (DataRow item in list.Tables[0].Rows)
            {
                #region
                v = new List<string>();
                v.Add(item["DDay"].ToString());
                v.Add(item["DDay"].ToString());
                v.Add(item["Counts"].ToString());
                v.Add(item["SXB"].ToString());
                v.Add(item["XM"].ToString());
                v.Add(item["MT"].ToString());
                v.Add(item["CS"].ToString());
                v.Add(item["XKQ"].ToString());
                v.Add(item["ST"].ToString());
                v.Add(item["TB"].ToString());
                v.Add(item["MZ"].ToString());
                v.Add(item["CT"].ToString());
                v.Add(item["CTUI"].ToString());
                v.Add(item["QT"].ToString());
                #endregion
                FlexiGridRow fgr = new FlexiGridRow()
                {
                    id = item["DDay"].ToString(),
                    cell = v
                };
                jsonFlexiGridData.rows.Add(fgr);
            }
            return Json(jsonFlexiGridData);
        }

        /// <summary>
        /// 报表导出
        /// </summary>
        /// <returns></returns>
        public ActionResult ReportOut(string Date)
        {
            return EContent(Date);
        }

        public ExcelContentResult EContent(string Date)
        {
            string[] sDate = new string[2];
            int icount = 0;
            sDate = Date.Split('-');
            int yy = Convert.ToInt32(sDate[0]);
            int mm = Convert.ToInt32(sDate[1]);
            StringBuilder sBuilder = new StringBuilder();
            //int totlerows = fundinfo.GetFundsOperatingDetailsReportCountWhere("");
            DataSet list = fundinfo.BindList(yy, mm, out icount);
            sBuilder.Append("<table cellspacing='0' cellpadding='5' rules='all' border='1'>");
            sBuilder.Append("<tr style='white-space: nowrap;'>");
            sBuilder.Append("<td colspan='13' style='font-size:25px; text-align:center;'>港盛公司洗衣房日报表(" + mm + "月)</td>");
            sBuilder.Append("</tr>");
            sBuilder.Append("<tr style='font-size:17px; white-space: nowrap;'>");
            sBuilder.Append("<td>日期</td>");
            sBuilder.Append("<td>数量</td>");
            sBuilder.Append("<td>水洗布</td>");
            sBuilder.Append("<td>涤棉</td>");
            sBuilder.Append("<td>棉套</td>");
            sBuilder.Append("<td>衬衫</td>");
            sBuilder.Append("<td>西裤(裙)</td>");
            sBuilder.Append("<td>食堂</td>");
            sBuilder.Append("<td>台布</td>");
            sBuilder.Append("<td>帽子</td>");
            sBuilder.Append("<td>车套</td>");
            sBuilder.Append("<td>尘推</td>");
            sBuilder.Append("<td>其它</td>");
            sBuilder.Append("</tr>");
            foreach (DataRow item in list.Tables[0].Rows)
            {
                sBuilder.Append("<tr style='font-size:14px; white-space: nowrap;'>");
                sBuilder.Append("<td>" + item["DDay"].ToString() + "</td>");
                sBuilder.Append("<td>" + item["Counts"].ToString() + "</td>");
                sBuilder.Append("<td>" + item["SXB"].ToString() + "</td>");
                sBuilder.Append("<td>" + item["XM"].ToString() + "</td>");
                sBuilder.Append("<td>" + item["MT"].ToString() + "</td>");
                sBuilder.Append("<td>" + item["CS"].ToString() + "</td>");
                sBuilder.Append("<td>" + item["XKQ"].ToString() + "</td>");
                sBuilder.Append("<td>" + item["ST"].ToString() + "</td>");
                sBuilder.Append("<td>" + item["TB"].ToString() + "</td>");
                sBuilder.Append("<td>" + item["MZ"].ToString() + "</td>");
                sBuilder.Append("<td>" + item["CT"].ToString() + "</td>");
                sBuilder.Append("<td>" + item["CTUI"].ToString() + "</td>");
                sBuilder.Append("<td>" + item["QT"].ToString() + "</td>");
                sBuilder.Append("</tr>");
            }
            sBuilder.Append("</table>");
            ExcelContentResult econtent = new ExcelContentResult();
            econtent.Content = sBuilder.ToString();
            econtent.filename = "XiYiDayReport";
            econtent.ContentType = "application/ms-excel";
            econtent.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
            return econtent;
        }
    }
}
